<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://struts.apache.org/tags-html-el" prefix="html-el" %>
<%@taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean-el" %>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@taglib uri="http://struts.apache.org/tags-logic-el" prefix="logic-el" %>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@taglib uri="/WEB-INF/tld/application.tld" prefix="app" %>

<style type="text/css">
	.swfupload {
		position: absolute;
		z-index: 1;
	}
</style>

<html-el:form action="/matricularAluno.do">
	<html-el:hidden property="method" styleId="method"/>
	<table style="width: 100%">
		<tr>
			<td align="center" valign="top">
				<!-- CONTENT -->			
				<div class="content">
					<table class="con">
						<tr>
							<td>
								<table class="breadory">
									<tr>
										<td>Matricular Aluno</td>
									</tr>
								</table>
								<br>
								<div style="width: 950px; height: 580px">
								    <div data-dojo-type="dijit.layout.TabContainer" style="width: 100%; height: 100%;" id="tabContainer">
								        <div data-dojo-type="dijit.layout.ContentPane" title="Aluno" selected="true" id="tabAluno">
								           
											<table style="width:100%;height:100%">
												<tr>
													<td valign="top">
														<table class="formulario" border="0">
															<tr>
																<td colspan="5">
																	<table class="breadorySub" style="width:300px">
																		<tr>
																			<td>1. Dados Gerais</td>
																		</tr>
																	</table>
																</td>
															</tr>
															<tr>
																<td class="required">CPF:</td>
																<td class="inputField" style="padding-left:7px"><input type="text" id="cpf" title="CPF" size="12" maxlength="14" onkeypress ="autoTab(this, event);" onblur="verificaCpf(this)"/></td>
															</tr>
															<tr>
																<td class="required">Nome:</td>
																<td class="inputField" style="padding-left:7px">
																	<input type="text" id="nome" title="Nome" size="50" maxlength="50" disabled="disabled"/>
																</td>
																<td style="width: 20px"></td>
																<td class="required">Data Nascimento:</td>
																<td class="inputField">
																	<input type="text"
																	style="font-size:14px;width:130px"
																	name="dataNascimento" id="dataNascimento" value="" disabled="disabled"
																	title="Data do Nascimento" constraints="{datePattern:'dd/MM/yyyy', strict:true}"
																	data-dojo-type="dijit.form.DateTextBox"	data-dojo-props="required:true, invalidMessage:'Data Inválida!'" />
																</td>
															</tr>
															<tr>
																<td class="required">RG:</td>
																<td colspan="8">
																	<table class="formulario" cellpadding="0" cellspacing="0">
																		<tr>
																			<td class="inputField">
																				<input type="text" id="rg" title="RG" size="12" maxlength="12" disabled="disabled"/>
																			</td>
																			<td style="width: 20px"></td>												
																			<td class="required">Orgão Exp:</td>
																			<td class="inputField">
																				<input type="text" id="orgaoExpeditor" title="Orgão Expeditor" size="6" maxlength="6" disabled="disabled"/>
																			</td>
																			<td style="width: 20px"></td>												
																			<td class="required">Sexo:</td>
																			<td class="inputField">
																				<app:comboSexo styleId="sexo" title="Sexo" disabled="true"/>
																			</td>
																			<td style="width: 20px"></td>
																			<td class="required">Deficiente:</td>
																			<td class="inputField">
																				<app:comboSimNao styleId="deficiente" title="Deficiente" disabled="true" selected="NAO"/>
																			</td>
																		</tr>
																	</table>
																</td>
															</tr>
														</table>
														<br>
														<table class="formulario">
															<tr>
																<td colspan="5">
																	<table class="breadorySub" style="width:300px">
																		<tr>
																			<td>2. Dados da CNH</td>
																		</tr>
																	</table>
																</td>
															</tr>
															<tr>
																<td colspan="8">
																	<table class="formulario">
																		<tr>
																			<td class="label">Registro/PGU:</td>
																			<td class="inputField">
																				<input type="text" id="pgu" title="Registro/PGU" size="10" disabled="disabled" maxlength="11"/>
																			</td>
																			<td style="width: 20px"></td>
																			<td class="label">Categoria:</td>
																			<td class="inputField">
																				<app:comboCategoriaCnh styleId="categoria" title="Categoria CNH" disabled="true" style="width:110px"/>
																			</td>
																			<td style="width: 20px"></td>
																			<td class="label">Data Primeira Habilitação:</td>
																			<td class="inputField">
																				<input type="text"
																				style="font-size:14px;width:130px"
																				id="dataPrimeiraHabilitacao" value="" disabled="disabled"
																				title="Data da Primeira Habilitação" constraints="{datePattern:'dd/MM/yyyy', strict:true}"
																				data-dojo-type="dijit.form.DateTextBox"	data-dojo-props="required:true, invalidMessage:'Data Inválida!'" />
																			</td>
																		</tr>
																	</table>
																</td>
															</tr>
														</table>
														<table class="formulario">
															<tr>
																<td colspan="8"><br>
																	<table class="breadorySub" style="width:300px">
																		<tr>
																			<td>3. Localização</td>
																		</tr>
																	</table>
																</td>
															</tr>
															<tr>
																<td class="required">CEP:</td>   
																<td class="inputField">
																	<input type="text" id="cep" title="CEP" size="5" maxlength="9" disabled="disabled" onblur="consultaCep(this)"/>
																</td>
															</tr>
															<tr>
																<td class="required">Endereço:</td>
																<td class="inputField">
																	<input type="text" id="endereco" title="Endereço" size="35" maxlength="50" disabled="disabled"/>
																</td>
																<td style="width: 20px"></td>
																<td class="required">Número:</td>
																<td class="inputField">
																	<input type="text" id="numero" title="Número" size="3" maxlength="5" disabled="disabled"/>
																</td>
																<td style="width: 20px"></td>
																<td class="label">Compl.:</td>
																<td class="inputField">
																	<input type="text" id="complemento" title="Complemento" size="3" maxlength="5" disabled="disabled"/>
																</td>
															</tr>
															<tr>
																<td class="required">Bairro:</td>
																<td class="inputField">
																	<input type="text" id="bairro" title="Bairro" size="20" maxlength="50" disabled="disabled"/>
																</td>
																<td style="width: 20px"></td>
																<td class="required">Cidade:</td>
																<td class="inputField">
																	<input type="text" id="cidade" title="Cidade" size="15" maxlength="50" value="" disabled="disabled"/>
																</td>
																<td style="width: 20px"></td>
																<td class="required">UF:</td>
																<td class="inputField">
																	<app:comboUF styleId="uf" title="UF" disabled="true" selected="SP" style="width:110px"/>
																</td>
															</tr>
														</table>
														<table class="formulario">
															<tr>
																<td colspan="8"><br>
																	<table class="breadorySub" style="width:300px">
																		<tr>
																			<td>4. Contato</td>
																		</tr>
																	</table>
																</td>
															</tr>
															<tr>
																<td class="label">Telefone:</td>
																<td class="inputField">
																	<input type="text" id="telefone" title="Telefone" size="8" disabled="disabled" style="width:120px"/>
																</td>
																<td style="width: 20px"></td>
																<td class="label">Celular:</td>
																<td class="inputField">
																	<input type="text" id="celular" title="Celular" size="8" disabled="disabled" style="width:120px"/>
																</td>
																<td style="width: 20px"></td>
																<td class="label">Comercial:</td>
																<td class="inputField">
																	<input type="text" id="comercial" title="Comercial" size="8" disabled="disabled" style="width:120px"/>
																</td>
															</tr>
															<tr>
																<td class="label">Email:</td>
																<td class="inputField" colspan="6">
																	<input type="text" id="email" title="Email" size="55" disabled="disabled" maxlength="50"/>
																</td>
															</tr>
														</table>
													</td>
												</tr>
												<tr>
													<td class="buttons" align="right" valign="bottom">	
														<a href="javascript:return" onclick="manterDadosAluno()" class="button">
															<span>Próximo</span>
														</a>
													</td>
												</tr>
											</table>         
								        </div>
								        <div data-dojo-type="dijit.layout.ContentPane" title="Curso" id="tabCurso">
									        <table style="width:100%;height:100%">
												<tr>
													<td valign="top">
														<table class="formulario">
															<tr>
																<td colspan="8">
														        	<table class="breadorySub" style="width:300px">
																		<tr>
																			<td>5. Dados do Curso</td>
																		</tr>
																	</table>
																</td>
															</tr>
															<tr>
																<td>
														            <table>
																		<tr>
																			<td>
																				<table style="display: inline" class="formulario">
																					<tr>
																						<td class="label">Curso:</td>
																						<td class="inputField">
																							<app:comboCurso styleId="curso" title="Curso" style="width:200px" onchange="selecionarCurso(this)" title="Curso"/>
																						</td>
																						<td style="width:20px"></td>
																						<td class="label">Tipo:</td>
																						<td class="inputField">
																							<app:comboTipoCurso styleId="tipoCurso" title="TipoCurso" disabled="true" onchange="selecionarTipoCurso(this)" style="width:250px"/>
																						</td>
																					</tr>
																					<tr>
																						<td colspan="5">
																							<br>
																							<table id="tbTurma" style="display: none">
																								<tr>
																									<td class="label">Turma:</td>
																									<td class="inputField">
																										<select id="turma" style="width:350px" title="Turma"/>
																									</td>
																								</tr>
																							</table>
																							<table id="tbEad" style="display: none">
																								<tr>
																									<td class="value"><i>O aluno deverá utilizar o email: <b>joao@email.com</b> para entrar no ambiente de estudo.</i></td>
																								</tr>
																								<tr>
																									<td class="value"><i>A senha inicial será enviada por email após a confirmação do pagamento.</i></td>
																								</tr>
																							</table>
																						</td>																						
																					</tr>
																				</table>
																			</td>
																		</tr>
																	</table>
																</td>
															</tr>
														</table>
														<br>
														<table class="formulario" border="0">
															<tr>
																<td colspan="2">															
																	<table class="breadorySub" style="width:300px">
																		<tr>
																			<td>6. Prova</td>
																		</tr>
																	</table>
																</td>
															</tr>
															<tr> 
																<td class="inputField" style="width:160px">
																	<input type="text" id="dataProva" value="" style="font-size:14px" onchange="verificaDataProva(this)" title="Data da Prova" constraints="{datePattern:'dd/MM/yyyy', strict:true, min:'${dataAtualDojo}'}" data-dojo-type="dijit.form.DateTextBox" data-dojo-props="required:true, invalidMessage:'Data Inválida!'"/>
																</td>
																<td align="left">
																	<select id="horaProva" style="width:120px; text-align: center" disabled="disabled" title="Horário da Prova"/>
																</td>
															</tr>
															<tr>
																<td colspan="2">
																	<table style="width: 500px">
																		<tr>
																			<td id="tbNaoProva" style="display: none" colspan="2">
																				<p style="color:#9D2E2C;font-size:14px;font-weight: bold">Para o curso selecionado, não é necessário a realização de prova!</p>
																			</td>
																		</tr>
																	</table>
																</td>																
															</tr>
														</table>
													</td>
												</tr>
												<tr>
													<td class="buttons" align="right" valign="bottom">	
														<a href="javascript:return" onclick="manterDadosCurso()" class="button">
															<span>Próximo</span>
														</a>
													</td>
												</tr>
											</table>
								        </div>
								        <div data-dojo-type="dijit.layout.ContentPane" title="Documentos" id="tabDocumentos">
								            <table style="width:100%;height:100%">
												<tr>
													<td valign="top">
														<table class="formulario">
															<tr>
																<td colspan="8">
														        	<table class="breadorySub" style="width:300px">
																		<tr>
																			<td>7. Digitalização</td>
																		</tr>
																	</table>
																</td>
															</tr>

															<tr>
																<td>
																	<table id="tbDocumentoExameMedico" style="display: none">
																		<tr>
																			<td class="label">- Exame Médico (xerox)</td>
																		</tr>
																	</table>	
																	<table id="tbDocumentoOficio" style="display: none">
																		<tr>
																			<td class="label">- Ofício</td>
																		</tr>
																	</table>
																	<table id="tbDocumentoRgCnh" style="display: none">
																		<tr>
																			<td class="label">- RG</td>
																		</tr>
																		<tr>
																			<td class="label">- CNH</td>
																		</tr>
																	</table>
																	<br>
																	<table>
																		<tr>
																			<td>
																				<div class="fieldset flash" id="fsUploadProgress">
																					<span class="legend">Fila de Envio</span>
																				</div>
																				<div id="divStatus">0 Arquivos Enviados</div>
																				<div>
																					<span id="spanButtonPlaceholder"></span>
																					<input id="btnUpload" type="button" value="Selecionar" style="width: 75px; height: 29px; font-size: 9pt;" />
																					<input id="btnCancel" type="button" value="Cancelar Todos os Envios" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />
																				</div>
																			</td>
																		</tr>
																	</table>																																								
																</td>
															</tr>																							
														</table>
													</td>
												</tr>
												<tr>
													<td align="left">
														<table class="breadory">
															<tr>
																<td>
																	<div id="galleryTop"></div>
																</td>
															</tr>
														</table>
													</td>
												</tr>
												<tr>
													<td class="buttons" align="right" valign="bottom">	
														<a href="javascript:return" onclick="manterDocumentos()" class="button">
															<span>Próximo</span>
														</a>
													</td>
												</tr>
											</table>
								        </div>
										<div data-dojo-type="dijit.layout.ContentPane" title="Histórico">
											<table style="width:100%;height:100%">
												<tr>
													<td valign="top">
														<table class="formulario">
															<tr>
																<td colspan="8">
													        		<table class="breadorySub" style="width:300px">
																		<tr>
																			<td>Cursos Realizados</td>
																		</tr>
																	</table>
																</td>
															</tr>
															<tr>
																<td>
																	<div id="conteudoHistorico" style="padding-top: -5">
																</td>
															</tr>
														</table>
													</td>
												</tr>
												<tr>
													<td class="buttons" align="right" valign="bottom">	
														<a href="javascript:return" onclick="dijit.byId('tabContainer').selectChild('tabPagamento')" class="button">
															<span>Próximo</span>
														</a>
													</td>
												</tr>
											</table>
								        </div>
										<div data-dojo-type="dijit.layout.ContentPane" title="Pagamento" id="tabPagamento">
											 <table style="width:100%;height:100%"> 
												<tr>
													<td valign="top">
														<table class="formulario" style="width: 100%">
															<tr>
																<td>
														        	<table class="breadorySub" style="width:300px">
																		<tr>
																			<td>8. Serviços</td>
																		</tr>
																	</table>
																</td>
															</tr>
															<tr>
																<td style="width: 100%">
																	<div id="conteudoServicos"></div>
																</td>
															</tr>
														</table>
													</td>
												</tr>
												<tr>
													<td style="height:300px" valign="top">
														<table class="formulario">
															<tr>
																<td colspan="2">
														        	<table class="breadorySub" style="width:300px">
																		<tr>
																			<td>9. Forma de Pagamento</td>
																		</tr>
																	</table>
																</td>
															</tr>
															<tr>
																<td style="width:20px;padding-right:5px; text-align: center">
														            <input type="radio" name="formaPagamento" id="formaPagamento" checked value="1" disabled="disabled" onclick="selecionaFormaPagamento(this)"/>
																</td>
																<td><b>Dinheiro</b></td>
															</tr>
															<tr>
																<td style="width:20px;padding-right:5px; text-align: center">
														            <input type="radio"name="formaPagamento" id="formaPagamento" value="2" disabled="disabled" onclick="selecionaFormaPagamento(this)"/>
																</td>
																<td><b>Cheque</b> (à vista | 5 dias | 10 dias)</td>
															</tr>															
															<tr>
																<td style="width:20px;padding-right:5px; text-align: center">
														            <input type="radio"name="formaPagamento" id="formaPagamento" value="3" disabled="disabled" onclick="selecionaFormaPagamento(this)"/>
																</td>
																<td><b>Não vai efetuar o pagamento neste momento</b></td>
															</tr>
															<tr>
																<td colspan="2">
																	<table class="formulario"> 
																		<tr>
																			<td class="required">Valor Pago:</td>
																			<td class="inputField">
																				<input type="text" id="valorPago" title="Valor a ser Pago" size="8" maxlength="8" style="text-align: right" onkeypress="return formatar_moeda(this,'.',',',event);" />
																			</td>
																		</tr>
																	</table>
																</td>
															</tr>
															<tr>
																<td colspan="2">
																	<table class="formulario" id="tbCheque" style="display:none">
																		<tr>
																			<td style="height:5px"></td> 
																		</tr>
																		<tr>
																			<td colspan="3">Dados Complementares - Cheque</td> 
																		</tr>
																		<tr>
																			<td class="required">Banco:</td>
																	        <td class="inputField" colspan="7">	
																	        	<app:comboBanco styleId="banco" style="width:400px" title="Banco"/>
																			</td>																																															
																		</tr>
																		<tr>
																			<td class="required">Agência:</td>
																			<td class="inputField">
																	            <input type="text" id="agenciaBanco" title="Agência" size="3" maxlength="4"/>
																			</td>
																			<td style="width: 10px"></td>
																			<td class="required">Conta:</td>
																			<td class="inputField">
																	            <input type="text" id="contaBanco" title="Conta Corrente" size="10" maxlength="10"/>
																			</td>
																			<td style="width: 10px"></td>
																			<td class="required">Cheque:</td>
																			<td class="inputField">
																	            <input type="text" id="chequeBanco" title="Número do Cheque" size="10" maxlength="10"/>
																			</td>
																			<td style="width: 10px"></td>																			
																			<td class="required">Data:</td>
																			<td class="inputField">
																	            <input type="text"
																					style="font-size:14px;width:120px"
																					name="dataCheque" id="dataCheque" value="" onchange="selecionaDataCheque()"
																					title="Data do Cheque" constraints="{datePattern:'dd/MM/yyyy', strict:true, min:'${dataAtualDojo}', max:'${data30Cheque}'}"
																					data-dojo-type="dijit.form.DateTextBox"	data-dojo-props="required:true, invalidMessage:'Data Inválida!'" />
																			</td>
																		</tr>
																		<tr>
																			<td style="height:10px"></td>
																		</tr>
																	</table>
																	<table id="tbJuroCheque" style="display: none">
																		<tr>
																			<td class="value">
																				<p style="color:#9D2E2C;font-size:14px;font-weight: bold">Para cheque com data maior que 15 dias, acréscimo de ${acrescimo15Dias}%</p>
																			</td>
																		</tr>
																	</table>
																</td>
															</tr>
														</table>
													</td>
												</tr>
												<tr>
													<td class="buttons" align="right" valign="bottom" id="btnConfirmar">	
														<a href="javascript:confirmarMatricula()" class="button">
															<span>Confirmar Matricula</span>
														</a>
													</td>
												</tr>
											</table>
								        </div>
								    </div>
								</div>
							</td>
						</tr>
					</table>
				</div>
			</td>
		</tr>
	</table>
	</html-el:form>

<script language="javascript">

	var codigoAluno = 0;

	jQuery(function($) {
		$("#cpf").mask("999.999.999/99");
		$("#dataNascimento").mask("99/99/9999");
		$("#orgaoExpeditor").mask("SSP/aa");
		$("#dataPrimeiraHabilitacao").mask("99/99/9999");
		$("#cep").mask("99999-999");
		$("#telefone").mask("(99)9999-9999");
		$("#celular").mask("(99)9999-9999");
		$("#comercial").mask("(99)9999-9999");
		$("#enderecoNumero").forceNumericOnly();
		$("#qtdeServico").forceNumericOnly();
		
		$("#agenciaBanco").forceNumericOnly();
		$("#contaBanco").forceNumericOnly();
		$("#chequeBanco").forceNumericOnly();
		
		$("#pgu").forceNumericOnly();
	});
	
	dojo.addOnLoad(function() {
		document.getElementById("cpf").focus();
		carregarServicos();
	});
	
	function verificaCpf(field) {
		if(field.value == "" || field.value == "___.___.___/__")
			return;
		
		if(!validateCPF(field))
			return;

		loading();
		require(["dojo/_base/lang", "dojo/_base/xhr"], function(lang, xhr) {
			xhr.post({
		        url: "consultarAluno.do?method=verificaCpf",
		        timeout: ${ajaxTimeoutReturn},
		        handleAs: "json",
		        content: {
		        	ajax: 'true',
		        	cpf:field.value
		        },
		        load: function(data, ioArgs) { 
		        	loadingComplete();
		        	if(data[0] == true) {
			        	document.getElementById("nome").value = data[1];
			        	dijit.byId("dataNascimento").set('value', data[2]);
			        	document.getElementById("sexo").value = data[3];
			        	document.getElementById("deficiente").value = data[4];
			        	document.getElementById("pgu").value = data[5];
			        	document.getElementById("categoria").value = data[6];
			        	dijit.byId("dataPrimeiraHabilitacao").set('value', value = data[7]);
			        	document.getElementById("cep").value = data[8];
			        	document.getElementById("endereco").value = data[9];
			        	document.getElementById("numero").value = data[10];
			        	document.getElementById("complemento").value = data[11];
			        	document.getElementById("bairro").value = data[12];
			        	document.getElementById("cidade").value = data[13];
			        	document.getElementById("uf").value = data[14];
			        	document.getElementById("telefone").value = data[15];
			        	document.getElementById("celular").value = data[16];
			        	document.getElementById("comercial").value = data[17];
			        	document.getElementById("email").value = data[18];
			        	document.getElementById("rg").value = data[19];
			        	document.getElementById("orgaoExpeditor").value = data[20];
			        	codigoAluno = data[21];
			        	initUpload();
			        	viewAllAttaches();
			        	carregarHistorico();
		        	}
		        	document.getElementById("nome").disabled = false;
		        	dijit.byId("dataNascimento").set('disabled', false);
		        	document.getElementById("sexo").disabled = false;
		        	document.getElementById("deficiente").disabled = false;
		        	document.getElementById("pgu").disabled = false;
		        	document.getElementById("categoria").disabled = false;
		        	dijit.byId("dataPrimeiraHabilitacao").set('disabled', false);
		        	document.getElementById("cep").disabled = false;
		        	document.getElementById("endereco").disabled = false;
		        	document.getElementById("numero").disabled = false;
		        	document.getElementById("complemento").disabled = false;
		        	document.getElementById("bairro").disabled = false;
		        	document.getElementById("cidade").disabled = false;
		        	document.getElementById("uf").disabled = false;
		        	document.getElementById("telefone").disabled = false;
		        	document.getElementById("celular").disabled = false;
		        	document.getElementById("comercial").disabled = false;
		        	document.getElementById("email").disabled = false;
		        	document.getElementById("rg").disabled = false;
		        	document.getElementById("orgaoExpeditor").disabled = false;
		        	document.getElementById("nome").focus();	        	
		        },
				error: function(data, ioArgs) {
					showAlertMessage("Erro ao realizar está operação! Tente novamente!");
		        }
		    });
		});		
	}
	
	function consultaCep(field) {
		
		if(field.value == "") {
			return;
		}
		loading();
		require(["dojo/_base/lang", "dojo/_base/xhr"], function(lang, xhr) {
			xhr.get({
		        url: "cep.do?method=consultaCep",
		        timeout: ${ajaxTimeoutReturn},
		        content: {
		        	ajax: 'true',
		        	cep:field.value
		        },
		        load: function(data, ioArgs) {
		        	loadingComplete();
		        	eval(data);
		        	if(unescape(resultadoCEP['resultado']) == "1") {
						document.getElementById("endereco").value = unescape(resultadoCEP['tipo_logradouro']) + " " + unescape(resultadoCEP['logradouro']);
						document.getElementById("cidade").value = unescape(resultadoCEP['cidade']);
						document.getElementById("bairro").value = unescape(resultadoCEP['bairro']);
						document.getElementById("uf").value = unescape(resultadoCEP['uf']);
						document.getElementById("numero").focus();
		        	} else {
		        		alert(unescape(resultadoCEP['resultado_txt']));
						document.getElementById("endereco").value = "";
						document.getElementById("numero").value = "";
						document.getElementById("complemento").value = "";
						document.getElementById("cidade").value = "";
						document.getElementById("bairro").value = "";
						document.getElementById("uf").value = "SP";
						field.focus();
		        	}
		        },
				error: function(data, ioArgs) {
					showAlertMessage("Erro ao realizar está operação! Tente novamente!");
		        }
		    });
		});
	}
	
	function manterDadosAluno() {
		
		if(!mandatoryField('cpf')) {
			return;
		}
		
		if(!validateCPF(document.getElementById("cpf")))
			return;
		
		if(!mandatoryField('nome')) {
			return;
		}
		if(!mandatoryField('dataNascimento')) {
			return;
		}
		if(!mandatoryField('rg')) {
			return;
		}
		if(!mandatoryField('orgaoExpeditor')) {
			return;
		}
		if(document.getElementById("orgaoExpeditor").value.length != 6) {
			alert("Orgão Expeditor inválido! O campo deve ter 5 caracteres.");
			return;
		}
		if(!mandatoryField('sexo')) {
			return;
		}		
		if(!mandatoryField('deficiente')) {
			return;
		}
		if(!mandatoryField('cep')) {
			return;
		}
		if(!mandatoryField('endereco')) {
			return;
		}
		if(!mandatoryField('numero')) {
			return;
		}		
		if(!mandatoryField('bairro')) {
			return;
		}
		if(!mandatoryField('cidade')) {
			return;
		}
		if(!mandatoryField('uf')) {
			return;
		}
			
		require(["dojo/_base/lang", "dojo/_base/xhr"], function(lang, xhr) {
			xhr.post({
		        url: "matricularAluno.do?method=manterDadosAluno",
		        timeout: ${ajaxTimeoutVoid},
		        handleAs: "json",
		        content: {
		        	ajax: 'true',
		        	codigo:codigoAluno,
		        	cpf: document.getElementById("cpf").value,
		        	nome: document.getElementById("nome").value,
		        	dataNascimento: document.getElementById("dataNascimento").value,
		        	rg: document.getElementById("rg").value,
		        	orgaoExpeditor: document.getElementById("orgaoExpeditor").value,
		        	sexo: document.getElementById("sexo").value,
		        	deficiente: document.getElementById("deficiente").value,
		        	pgu: document.getElementById("pgu").value,
		        	categoria: document.getElementById("categoria").value,
		        	dataPrimeiraHabilitacao: document.getElementById("dataPrimeiraHabilitacao").value,
		        	cep: document.getElementById("cep").value,
		        	endereco: document.getElementById("endereco").value,
		        	numero: document.getElementById("numero").value,
		        	complemento: document.getElementById("complemento").value,
		        	bairro: document.getElementById("bairro").value,
		        	cidade: document.getElementById("cidade").value,
		        	uf: document.getElementById("uf").value,
		        	telefone: document.getElementById("telefone").value,
		        	celular: document.getElementById("celular").value,
		        	comercial: document.getElementById("comercial").value,
		        	email: document.getElementById("email").value
		        },
		        load: function(data) {
		        	codigoAluno = data[0];
		    		dijit.byId('tabContainer').selectChild('tabCurso');
		        	initUpload();
		        },
				error: function(data, ioArgs) {
					showAlertMessage("Erro ao realizar está operação! Tente novamente!");
		        }
		    });
		});
	}
	
	var swfu;
	function initUpload() {
		
		var settings = {
			flash_url : "_scripts/jquery-1.7.1/swfupload/swfupload.swf",
			upload_url: "anexoAluno?action=upload&usuario=${usuario.codigo}&aluno="+codigoAluno,
			file_size_limit : "1 MB",
			file_types : "*.*",
			file_types_description : "Todos os arquivos",
			file_upload_limit : 100,
			file_queue_limit : 0,
			custom_settings : {
				progressTarget : "fsUploadProgress",
				cancelButtonId : "btnCancel"
			},
			debug: false,

			// Button settings
			button_placeholder_id : "spanButtonPlaceholder",
			button_width: 61,
			button_height: 22,
			button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
			button_cursor: SWFUpload.CURSOR.HAND,
			
			// The event handler functions are defined in handlers.js
			file_queued_handler : fileQueued,
			file_queue_error_handler : fileQueueError,
			file_dialog_complete_handler : fileDialogComplete,
			upload_start_handler : uploadStart,
			upload_progress_handler : uploadProgress,
			upload_error_handler : uploadError,
			upload_success_handler : uploadSuccess,
			upload_complete_handler : uploadComplete,
			queue_complete_handler : queueComplete,	// Queue plugin event
			
			// SWFObject settings
			minimum_flash_version : "9.0.28",
			swfupload_pre_load_handler : swfUploadPreLoad,
			swfupload_load_failed_handler : swfUploadLoadFailed
		};

		swfu = new SWFUpload(settings);
	}
	
	function uploadSuccess(file, serverData) {
		try {
			var progress = new FileProgress(file, this.customSettings.progressTarget);
			progress.setComplete();
			progress.setStatus("Complete.");
			progress.toggleCancel(false);

			document.getElementById("galleryTop").innerHTML = serverData;
			$('#gallery a').lightBox();	
		} catch (ex) {
			this.debug(ex);
		}
	}
	
	function viewAllAttaches() {
		require(["dojo/_base/lang", "dojo/_base/xhr"], function(lang, xhr) {
			xhr.get({
		        url: "anexoAluno",
		        timeout: ${ajaxTimeoutData},
		        content: {
		        	ajax: 'true',
		        	action: "render",
		        	aluno: codigoAluno
		        },
		        load: function(data, ioArgs) {
					document.getElementById("galleryTop").innerHTML = data;
					$('#gallery a').lightBox();	
		        },
				error: function(data, ioArgs) {
					showAlertMessage("Erro ao realizar está operação! Tente novamente!");
		        }
		    });
		});
	}
	
	function carregarHistorico() {
		require(["dojo/_base/lang", "dojo/_base/xhr"], function(lang, xhr) {
			xhr.get({
		        url: "consultarAluno.do?method=carregarHistorico",
		        timeout: ${ajaxTimeoutData},
		        content: {
		        	ajax: 'true',
		        	aluno: codigoAluno
		        },
		        load: function(data, ioArgs) {
					document.getElementById("conteudoHistorico").innerHTML = data;
		        },
				error: function(data, ioArgs) {
					showAlertMessage("Erro ao realizar está operação! Tente novamente!");
		        }
		    });
		});
	}	
	
	function excluirAnexo(codigo) {
		require(["dojo/_base/lang", "dojo/_base/xhr"], function(lang, xhr) {
			xhr.get({
		        url: "anexo.do?method=excluir",
		        timeout: ${ajaxTimeoutVoid},
		        content: {
		        	ajax: 'true',
		        	tipo: 2,
		        	codigo: codigo
		        },
		        load: function(data, ioArgs) {
		        	viewAllAttaches();
		        },
				error: function(data, ioArgs) {
					showAlertMessage("Erro ao realizar está operação! Tente novamente!");
		        }
		    });
		});
		
	}
	
	function selecionarCurso(f) {
		tbDocumentoExameMedico.style.display = "none";
		tbDocumentoOficio.style.display = "none";
		tbDocumentoRgCnh.style.display = "none";
		tbNaoProva.style.display = "none";
		tbTurma.style.display = "none";
		document.getElementById("turma").disabled = true;
    	document.getElementById("turma").options.length = 0;
		
		if(f.value == "3" || f.value == "1") {//renovacao | primeira habilitacao
			tbDocumentoExameMedico.style.display = "inline";
			if(f.value == "1") { //primeira habilitacao
				tbNaoProva.style.display = "inline";
				document.getElementById("horaProva").disabled = true;
				dijit.byId("dataProva").set("disabled", true);
				document.getElementById("dataProva").value = "";
			}
		}
		if(f.value == "2") {//reciclagem
			tbDocumentoOficio.style.display = "inline";
			dijit.byId("dataProva").set("disabled", false);
			document.getElementById("dataProva").value = "";
			document.getElementById("horaProva").disabled = false;
		}
		if(f.value == "3") { //renovacao
			dijit.byId("dataProva").set("disabled", false);
			document.getElementById("horaProva").disabled = false;
		}
		if(f.value == "4") {//taxi
			tbDocumentoRgCnh.style.display = "inline";
			tbNaoProva.style.display = "inline";
			document.getElementById("horaProva").disabled = true;
			dijit.byId("dataProva").set("disabled", true);
			document.getElementById("dataProva").value = "";
		}
		

		if(f.value == "1" || f.value == "2" || f.value == 4) { //primeira habilitacao | reciclagem | taxi
			document.getElementById("tipoCurso").value = "1";
			document.getElementById("tipoCurso").disabled = true;
			selecionarTipoCurso(document.getElementById("tipoCurso"));
		} else {
			document.getElementById("tipoCurso").disabled = false;
			document.getElementById("tipoCurso").value = "";
		}
		
	}
	
	function selecionarTipoCurso(f) {
		tbEad.style.display = "none";
		tbTurma.style.display = "none";
		document.getElementById("turma").disabled = true;
    	document.getElementById("turma").options.length = 0;
    	
		if(f.value == "1") { //presencial
			//Consulta Turma Disponivel
			require(["dojo/_base/lang", "dojo/_base/xhr"], function(lang, xhr) {
				xhr.post({
			        url: "cadastroTurma.do?method=consultaProximaDisponivel",
			        timeout: ${ajaxTimeoutReturn},
			        handleAs: "json",
			        content: {
			        	ajax: 'true',
			        	curso: document.getElementById("curso").value
			        },
			        load: function(data, ioArgs) {
			        	
			        	var result = data;
			        	if(result[0] == false) {
			        		alert(result[1]);
			        		document.getElementById("turma").disabled = true;
				        	document.getElementById("turma").options.length = 0;
			        		return false;
			        	}
			        	
			        	var list = data[1]; //turmas
		        		document.getElementById("turma").disabled = false;
			        	document.getElementById("turma").options.length = 0;
			        	document.getElementById("turma").options[0] = new Option("Selecione...", "");
			        	for(i=0; i<list.length; i++) {
			        		document.getElementById("turma").options[i+1] = new Option(list[i][1], list[i][0]);
			        	}	        	
			        },
					error: function(data, ioArgs) {
						showAlertMessage("Erro ao realizar está operação! Tente novamente!");
			        }
			    });
			});			
			
			tbTurma.style.display = "inline";
		} 
		if(f.value == "2") { //ead
			tbEad.style.display = "inline";
		}			
	}
	
	function verificaDataProva(field) {
		var dataInformada = document.getElementById(field.id).value;
		
		if(dataInformada == "" || dataInformada == "01/01/1970")
			return;
		
		if(dataInformada.length != 10) {
			alert("Data Inválida.\n Favor informar a data no formato dd/mm/aaaa.");
			document.getElementById(field.id).focus();
			return;
		}
		
		require(["dojo/_base/lang", "dojo/_base/xhr"], function(lang, xhr) {
			xhr.post({
		        url: "matricularAluno.do?method=verificaDataProva",
		        timeout: ${ajaxTimeoutReturn},
		        handleAs: "json",
		        content: {
		        	ajax: 'true',
		        	dataProva: dataInformada
		        },
		        load: function(data, ioArgs) {
		        	
		        	var result = data;
		        	if(result[0] == false) {
		        		alert(result[1]);
		        		document.getElementById(field.id).value = "";
		        		return false;
		        	}
		        	
		        	var list = data[1]; //horarios
	        		document.getElementById("horaProva").disabled = false;
		        	document.getElementById("horaProva").options.length = 0;
		        	document.getElementById("horaProva").options[0] = new Option("Selecione...", "");
		        	for(i=0; i<list.length; i++) {
		        		document.getElementById("horaProva").options[i+1] = new Option(list[i], list[i]);
		        	}
		        },
				error: function(data, ioArgs) {
					showAlertMessage("Erro ao realizar está operação! Tente novamente!");
		        }
		    });
		});		
	}
	
	function manterDadosCurso() {
		
		if(!mandatoryField('curso')) {
			return;
		}		
		if(!mandatoryField('tipoCurso')) {
			return;
		}
		
		if(document.getElementById("tipoCurso").value == 1) {//presencial
			if(!mandatoryField('turma')) {
				return;
			}
		}
		
		if(document.getElementById("curso").value == 3) { //renovacao - obrigatorio prova
			if(!mandatoryField('dataProva')) {
				return;
			}
			if(!mandatoryField('horaProva')) {
				return;
			}
		}
		
		require(["dojo/_base/lang", "dojo/_base/xhr"], function(lang, xhr) {
			xhr.get({
		        url: "matricularAluno.do?method=incluirCurso",
		        timeout: ${ajaxTimeoutReturn},
		        handleAs: "json",
		        content: {
		        	ajax: 'true',
		        	cpf: document.getElementById("cpf").value,
		        	curso: document.getElementById("curso").value,
		        	tipoCurso: document.getElementById("tipoCurso").value,
		        	turma: document.getElementById("turma").value
		        },
		        load: function(data, ioArgs) {
		        	if(data[0] == true) {
						carregarServicos();
						habilitaFormaPagamento();
						dijit.byId('tabContainer').selectChild('tabDocumentos');
		        	} else {
		        		alert(data[1]);
		        		return;
		        	}
		        },
				error: function(data, ioArgs) {
					showAlertMessage("Erro ao realizar está operação! Tente novamente!");
		        }
		    });
		});
	}
	
	var acrescimoServicos = 0;
	
	function carregarServicos() {		
		require(["dojo/_base/lang", "dojo/_base/xhr"], function(lang, xhr) {
			xhr.get({
		        url: "servico.do?method=carregarServicos",
		        timeout: ${ajaxTimeoutData},
		        content: {
		        	ajax: 'true',
		        	acrescimoServicos: acrescimoServicos
		        },
		        load: function(data, ioArgs) {
					document.getElementById("conteudoServicos").innerHTML = data;
					document.getElementById("valorPago").value = document.getElementById("valorPagoTemp").value;
		        },
				error: function(data, ioArgs) {
					showAlertMessage("Erro ao realizar está operação! Tente novamente!");
		        }
		    });
		});
	}	
	
	function manterDocumentos() {
		dijit.byId('tabContainer').selectChild('tabPagamento');
		document.getElementById("valorPago").focus();
	}
	
	function selecionaFormaPagamento(field) {
		
		document.getElementById("banco").value = "";
		document.getElementById("agenciaBanco").value = "";
		document.getElementById("contaBanco").value = "";
		document.getElementById("chequeBanco").value = "";
		document.getElementById("dataCheque").value = "";
		document.getElementById("valorPago").disabled = true;
		
		document.getElementById("valorPago").value = document.getElementById("valorPagoTemp").value;
		
		acrescimoServicos = 0;
		carregarServicos();
		
		tbCheque.style.display = 'none';
		if(field.value == 1 || field.value == 3) {
			tbCheque.style.display = 'none';
		} else {
			tbCheque.style.display = 'inline'
			document.getElementById("banco").focus();
		}
		
		if(field.value == 1) {
			document.getElementById("valorPago").disabled = false;
		}
	}
	
	function habilitaFormaPagamento() {
		document.forms[0].formaPagamento[0].disabled = false; //dinheiro
		document.forms[0].formaPagamento[1].disabled = false; //cheque
		document.forms[0].formaPagamento[2].disabled = false; //depois
	}
	
	function selecionaDataCheque() {
		var dataCheque15dias = '${data15Cheque}';
		var dia = parseInt(dataCheque15dias.substring(8,10));
		var mes = parseInt(dataCheque15dias.substring(6,7));
		var ano = parseInt(dataCheque15dias.substring(0,5));
		var data15 = new Date();
		data15.setFullYear(ano, --mes, dia);
		
		var dataSelecionada = document.getElementById("dataCheque").value;
		dia = parseInt(dataSelecionada.substring(0,2));
		mes = parseInt(dataSelecionada.substring(3,5));
		ano = parseInt(dataSelecionada.substring(6,10));
		dataSelecionada = new Date();
		dataSelecionada.setFullYear(ano, --mes, dia);
		
		document.getElementById("tbJuroCheque").style.display = "none";
		acrescimoServicos = 0;
		if(dataSelecionada > data15) {
			document.getElementById("tbJuroCheque").style.display ="inline";
			acrescimoServicos = ${acrescimo15Dias};
		}
		carregarServicos();
	}
	
	function confirmarMatricula() {
		
		if(codigoAluno == null || codigoAluno == 0) {
			alert("Cadastro do Aluno incompleto. Favor verificar!");
			dijit.byId('tabContainer').selectChild('tabAluno');
			return;
		}
		
		if(document.forms[0].formaPagamento[1].checked == true) {
			if(!mandatoryField('banco')) {
				return;
			}
			if(!mandatoryField('agenciaBanco')) {
				return;
			}
			if(!mandatoryField('contaBanco')) {
				return;
			}
			if(!mandatoryField('chequeBanco')) {
				return;
			}
			if(!mandatoryField('dataCheque')) {
				return;
			}
		} else if(document.forms[0].formaPagamento[2].checked == true) {
			if(!confirm("Confirma o não recebimento do pagamento ?\nO aluno deverá efetuar o pagamento no primeiro dia de aula!")) {
				return;
			}
		}
		
		if(!mandatoryField('curso')) {
			dijit.byId('tabContainer').selectChild('tabCurso');
			return;
		}		
		if(!mandatoryField('tipoCurso')) {
			dijit.byId('tabContainer').selectChild('tabCurso');
			return;
		}
		
		if(document.getElementById("tipoCurso").value == 1) {//presencial
			if(!mandatoryField('turma')) {
				dijit.byId('tabContainer').selectChild('tabCurso');
				return;
			}
		} 
		
		if(document.getElementById("curso").value == 3) { //renovacao - obrigatorio prova
			if(!mandatoryField('dataProva')) {
				dijit.byId('tabContainer').selectChild('tabCurso');
				return;
			}
			if(!mandatoryField('horaProva')) {
				dijit.byId('tabContainer').selectChild('tabCurso'); 
				return;
			}
		}
		
		var valorPagoServico = document.getElementById("valorPagoTemp").value;
		while(valorPagoServico.indexOf(".") > 0) {
			valorPagoServico = valorPagoServico.replace('.','');
		}
		valorPagoServico = valorPagoServico.replace(',','.');
		
		var valorPago = document.getElementById("valorPago").value;
		while(valorPago.indexOf(".") > 0) {
			valorPago = valorPago.replace('.','');
		}
		valorPago = valorPago.replace(',','.');
		
		if(parseFloat(valorPago) > parseFloat(valorPagoServico)) {
			if(!confirm("O Valor a ser pago é MAIOR que o Valor total dos Serviços! Deseja continuar?"))
				return;
		}		
		
		var formaPagamento = 0;
		if(document.forms[0].formaPagamento[0].checked) {
			formaPagamento = 1;
		} else if(document.forms[0].formaPagamento[1].checked) {
			formaPagamento = 2;
		} else if(document.forms[0].formaPagamento[2].checked) {
			formaPagamento = 3;
		}
		
		var nomeAluno = document.getElementById("nome");
		if(!confirm("Confirma a Matricula do aluno: " + nomeAluno.value + " ?"))
			return;
		
		require(["dojo/_base/lang", "dojo/_base/xhr"], function(lang, xhr) {
			xhr.get({
		        url: "matricularAluno.do?method=matricular",
		        timeout: ${ajaxTimeoutVoid},
		        content: {
		        	ajax: 'true',
		        	codigo: codigoAluno,
		        	curso: document.getElementById("curso").value,
		        	tipoCurso: document.getElementById("tipoCurso").value,
		        	turma: document.getElementById("turma").value,
		        	dataProva: document.getElementById("dataProva").value,
		        	horaProva: document.getElementById("horaProva").value,
		        	formaPagamento: formaPagamento,
		        	banco: document.getElementById("banco").value,
		        	agencia: document.getElementById("agenciaBanco").value,
		        	conta: document.getElementById("contaBanco").value,
		        	cheque: document.getElementById("chequeBanco").value,
		        	dataCheque : document.getElementById("dataCheque").value,
		        	valorPagamento: document.getElementById("valorPago").value
		        },
		        load: function(data, ioArgs) {
		        	alert("Matricula efetuada com sucesso!");
		        	window.open('reportPrint.do?method=print');
		        	window.location = "login.do?method=home";
		        	
		        },
				error: function(data, ioArgs) {
					showAlertMessage("Erro ao realizar está operação! Tente novamente!");
		        }
		    });
		});	
	}
	
</script>